home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Collection of Tools & Utilities
/
Collection of Tools and Utilities.iso
/
edit
/
tde40.zip
/
main.c
< prev
next >
Wrap
C/C++ Source or Header
|
1994-06-05
|
23KB
|
799 lines
/******************* start of original comments ********************/
/*
* Written by Douglas Thomson (1989/1990)
*
* This source code is released into the public domain.
*/
/*
* Name: dte - Doug's Text Editor program - hardware dependent module
* Purpose: This file contains all the code that needs to be different on
* different hardware.
* File: hwibm.c
* Author: Douglas Thomson
* System: This particular version is for the IBM PC and close compatibles.
* It write directly to video RAM, so it is faster than other
* techniques, but will cause "snow" on most CGA cards. See the
* file "hwibmcga.c" for a version that avoids snow.
* The compiler is Turbo C 2.0, using one of the large data memory
* models.
* Date: October 10, 1989
* Notes: This module has been kept as small as possible, to facilitate
* porting between different systems.
*/
/********************* end of original comments ********************/
/*
* These routines were rewritten for Microsoft C. They are pretty much system
* dependent and pretty much Microsoft C dependent. I also renamed this file
* "main.c" - easier to find the main function.
*
* New editor name: TDE, the Thomson-Davis Editor.
* Author: Frank Davis
* Date: June 5, 1991, version 1.0
* Date: July 29, 1991, version 1.1
* Date: October 5, 1991, version 1.2
* Date: January 20, 1992, version 1.3
* Date: February 17, 1992, version 1.4
* Date: April 1, 1992, version 1.5
* Date: June 5, 1992, version 2.0
* Date: October 31, 1992, version 2.1
* Date: April 1, 1993, version 2.2
* Date: June 5, 1993, version 3.0
* Date: August 29, 1993, version 3.1
* Date: November 13, 1993, version 3.2
* Date: June 5, 1994, version 4.0
*
* This modification of Douglas Thomson's code is released into the
* public domain, Frank Davis. You may distribute it freely.
*/
char *greatest_composer_ever = "W. A. Mozart, 1756-1791";
#include "tdestr.h" /* tde types */
#include "common.h"
#include "define.h"
#include "help.h"
#include "tdefunc.h"
#include <fcntl.h> /* open flags */
#if defined( __UNIX__ )
#include <signal.h> /* unix critical errors */
#else
#include <dos.h> /* for renaming files */
#include <bios.h> /* for direct BIOS keyboard input */
#include <io.h> /* for file attribute code */
#if defined( __MSC__ )
#include <errno.h>
#include <sys\types.h> /* S_IWRITE etc */
#endif
#include <sys\stat.h> /* S_IWRITE etc */
#endif
#if defined( __MSC__ )
void (interrupt FAR *old_control_c)( ); /* variable for old CNTL-C */
void (interrupt FAR *old_int1b)( ); /* variable for old int 1b */
#endif
/*
* original control-break checking flag
*/
static int s_cbrk;
/*
* Name: main
* Purpose: To do any system dependent command line argument processing,
* and then call the main editor function.
* Date: October 10, 1989
* Passed: argc: number of command line arguments
* argv: text of command line arguments
*/
int main( int argc, char *argv[] )
{
#if defined( __MSC__ )
union REGS inregs, outregs;
#endif
g_status.found_first = FALSE;
g_status.arg = 1;
g_status.argc = argc;
g_status.argv = argv;
#if defined( __UNIX__ )
/*
* unix signals are kinda analagous to DOS critical errors.
*/
/*
signal( SIGABRT, crit_err_handler );
signal( SIGALRM, crit_err_handler );
signal( SIGCHLD, crit_err_handler );
signal( SIGCONT, crit_err_handler );
signal( SIGFPE, crit_err_handler );
signal( SIGHUP, crit_err_handler );
signal( SIGILL, crit_err_handler );
signal( SIGINT, crit_err_handler );
signal( SIGIO, crit_err_handler );
signal( SIGIOT, crit_err_handler );
signal( SIGKILL, crit_err_handler );
signal( SIGPIPE, crit_err_handler );
signal( SIGPOLL, crit_err_handler );
signal( SIGPWR, crit_err_handler );
signal( SIGQUIT, crit_err_handler );
signal( SIGSEGV, crit_err_handler );
signal( SIGSTOP, crit_err_handler );
signal( SIGTERM, crit_err_handler );
signal( SIGTRAP, crit_err_handler );
signal( SIGTSTP, crit_err_handler );
signal( SIGTTIN, crit_err_handler );
signal( SIGTTOU, crit_err_handler );
signal( SIGURG, crit_err_handler );
signal( SIGUSR1, crit_err_handler );
signal( SIGUSR2, crit_err_handler );
signal( SIGVTALRM, crit_err_handler );
signal( SIGWINCH, crit_err_handler );
signal( SIGXCPU, crit_err_handler );
signal( SIGXFSZ, crit_err_handler );
*/
#else
/*
* trap control-break to make it harmless, and turn checking off.
* trap control-C to make it harmless.
*/
# if defined( __MSC__ )
inregs.h.ah = 0x33;
inregs.h.al = 0;
intdos( &inregs, &outregs );
s_cbrk = outregs.h.dl;
old_control_c = _dos_getvect( (unsigned)0x23 );
_dos_setvect( 0x23, harmless );
old_int1b = _dos_getvect( (unsigned)0x1b );
_dos_setvect( 0x1b, ctrl_break );
inregs.h.ah = 0x33;
inregs.h.al = 1;
inregs.h.dl = 0;
intdos( &inregs, &outregs );
# else
s_cbrk = getcbrk( );
ctrlbrk( harmless );
setcbrk( 0 );
# endif
/*
* now, install and initialize our simple Critical Error Handler.
*/
install_ceh( &ceh );
#endif
ceh.flag = OK;
if (initialize( ) != ERROR)
editor( );
terminate( );
return( 0 );
}
/*
* Name: error
* Purpose: To report an error, and usually make the user type <ESC> before
* continuing.
* Date: June 5, 1991
* Passed: kind: an indication of how serious the error was:
* WARNING: continue after pressing a key
* FATAL: abort the editor
* line: line to display message
* message: string to be printed
* Notes: Show user the message and ask for a key if needed.
*/
void error( int kind, int line, char *message )
{
char buff[MAX_COLS+2]; /* somewhere to store error before printing */
#if defined( __UNIX__ )
chtype display_buff[MAX_COLS+2]; /* chtype is defined in curses.h */
#else
char display_buff[(MAX_COLS+2)*2];
#endif
/*
* tell the user what kind of an error it is
*/
switch (kind) {
case FATAL:
/*
* fatal error
*/
assert( strlen( main1 ) < (size_t)g_display.ncols );
strcpy( buff, main1 );
break;
case WARNING:
default:
/*
* warning
*/
assert( strlen( main2 ) < (size_t)g_display.ncols );
strcpy( buff, main2 );
break;
}
/*
* prepare the error message itself
*/
strcat( buff, message );
/*
* tell the user how to continue editing if necessary
*/
if (kind == WARNING)
/*
* press a key
*/
strcat( buff, main3 );
/*
* output the error message
*/
save_screen_line( 0, line, display_buff );
set_prompt( buff, line );
if (kind == FATAL) {
/*
* no point in making the user type <ESC>, since the program is
* about to abort anyway...
*/
terminate( );
exit( 1 );
}
getkey( );
restore_screen_line( 0, line, display_buff );
if (g_status.wrapped) {
g_status.wrapped = FALSE;
show_search_message( CLR_SEARCH, g_display.mode_color );
}
}
/*
* Name: harmless
* Purpose: Do nothing when control-C is pressed
* Date: June 5, 1991
* Notes: Interrupt 23, the Control-C handler, is a MS DOS system function.
* Since we want to use Control-C as a regular function key,
* let's do absolutely nothi